package com.mall.shopping.services;

import com.mall.shopping.IProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dal.entitys.ItemDesc;
import com.mall.shopping.dal.persistence.ItemDescMapper;
import com.mall.shopping.dal.persistence.ItemMapper;
import com.mall.shopping.dto.ProductDetailDto;
import com.mall.shopping.dto.ProductDetailRequest;
import com.mall.shopping.dto.ProductDetailResponse;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

//查看商品详情


@Component
@Service(interfaceClass = IProductService.class)
public class IProductServiceImp implements IProductService {

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    ItemDescMapper itemDescMapper;

    //商品明细
    @Override
    public ProductDetailResponse getProductDetail(ProductDetailRequest request) {
        Long id = request.getId();
        //通过ID获取商品大概的详情
        List<ProductDetailDto> productDetailDtoList = itemMapper.selectProductDetailByPrimaryKey(id);
        ProductDetailDto productDetailDto = productDetailDtoList.get(0);

        //查询表ItemDesc信息获大图的具体尺寸信息
        ItemDesc itemDesc = itemDescMapper.selectByPrimaryKey(id);
        String imageDesc = itemDesc.getItemDesc();

        //获取大图和尺寸
        String indexPic = productDetailDto.getProductImageSmall().get(0);
        productDetailDto.setProductImageBig(indexPic);
        productDetailDto.setDetail(imageDesc);

        //response对象
        ProductDetailResponse response = new ProductDetailResponse();
        response.setProductDetailDto(productDetailDto);
        response.setCode(ShoppingRetCode.SUCCESS.getCode());
        response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return response;

    }

//    @Override
//    public AllProductResponse getAllProduct(AllProductRequest request) {
//        return null;
//    }
//
//    @Override
//    public RecommendResponse getRecommendGoods() {
//        return null;
//    }
}
